package com.hsp.demo_08_object_test;

public class Demo_01 {
    public static void main(String[] args) {
        /*
        1、定义一个person类（name, age, job), 初始化Person对象数组，有3个person对象，并
        按照age从大到小进行排序，提示，使用冒泡排序。
         */

        Person[] p = new Person[4];

        p[0] = new Person("jack", 18, "程序猿");
        p[1] = new Person("rose", 20, "服务员");
        p[2] = new Person("tom", 35, "伐木工");
        p[3] = new Person("bin", 50, "老板");

        Person p2 = new Person();
        for(int i = 0; i < p.length; i++){
            for(int j = 0; j < p.length - 1 - i; j++){
                if(p[j].getAge() < p[j+1].getAge()){
                    p2 = p[j];
                    p[j] = p[j+1];
                    p[j+1] = p2;
                }
            }
        }

        for (int i = 0; i < p.length; i++) {
            System.out.println(p[i].toString());
        }

    }
}

class Person{
    private String name;
    private int age;
    private String job;

    public Person(){}

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }
}